<?php
class SliderHelper extends AppHelper {
	
	var $name = "Slider";
	
	var $defaultOptions = array('value'=>'100', 'min'=>'0', 'max'=>'500', 'step'=>'50');
	
	function generateOutput($options, $sliderOptions)
	{
		$this->addJUI();
		
		if(empty($sliderOptions))
		{
			$sliderOptions = $this->defaultOptions;
		}
		
		$sliderId = "slider_".mt_rand();
		
		//unset($options['tooltip']);
		$options['type'] = 'text';
		
		$options['style'] = 'border:0;';
		
		$return = array();
		$sliderChangeCallback = '';
		if(isset($options['onSliderChange']))
		{
			$sliderChangeCallback = $options['onSliderChange'];
		}
		
		$return['output'] = '<div id="'.$sliderId.'"></div><script>$(document).ready(function(){
			$("#'.$sliderId.'").slider({
				value: '.$sliderOptions['value'].',
				min: '.$sliderOptions['min'].',
				max: '.$sliderOptions['max'].',
				step: '.$sliderOptions['step'].',
				slide: 	function(event, ui) {
							$("#'.$options['id'].'").val(ui.value);
							'.$sliderChangeCallback.'(event, ui);
						}
			});
		});</script>';
		$return['options'] = $options;
		return $return;
	}

	function plain($id,$sliderOptions)
	{
		$this->addJUI();
		$defaults = am($this->defaultOptions,array('stop'=>'','slide'=>''));
		$sliderOptions = am($defaults,$sliderOptions);
		$options = '{';
		foreach($sliderOptions as $name => $opt)
		{
			$options .= $name.': '.$opt.',';
		}
		$options .= '}';
		$out = '<script type="text/javascript">$(document).ready(function(){$("#'.$id.'").slider('.$options.')})</script>';
		return $out;
	}
	
}
?>